console.log('------------------------------------------');
const str1 = 'hello world';
console.log(str1[Symbol.iterator]);//[Function: [Symbol.iterator]]
const map1 = new Map([['key1','value1']]);
console.log(map1[Symbol.iterator]);//[Function: entries]
console.log('------------------------------------------');
const num = 45;
const obj = {};
console.log(num[Symbol.iterator]);//undefined
console.log(obj[Symbol.iterator]);//undefined
console.log('----------------------------------------------');
const str = 'abc';
const arr = ['a','b','c'];
const map = new Map().set('a',1).set('b',2).set('c',3);
const set = new Set().add('a').add('b').add('c');
console.log(str[Symbol.iterator]);
console.log(arr[Symbol.iterator]);
console.log(map[Symbol.iterator]);
console.log(set[Symbol.iterator]);
// [Function: [Symbol.iterator]]
// [Function: values]
// [Function: entries]
// [Function: values]
console.log(str[Symbol.iterator]());
console.log(arr[Symbol.iterator]());
console.log(map[Symbol.iterator]());
console.log(set[Symbol.iterator]());
// Object [String Iterator] {}
// Object [Array Iterator] {}
// [Map Entries] { [ 'a', 1 ], [ 'b', 2 ], [ 'c', 3 ] }
// [Set Iterator] { 'a', 'b', 'c' }
console.log('=======================================================');
//可迭代对象
let arr1 = ['foo','bar'];
//迭代器工厂函数
console.log(arr1[Symbol.iterator]);//[Function: values]
//迭代器
let iter = arr1[Symbol.iterator]();
console.log(iter);//Object [Array Iterator] {}
console.log(iter.next());//{ value: 'foo', done: false }
console.log(iter.next());//{ value: 'bar', done: false }
console.log(iter.next());//{ value: undefined, done: true }
console.log('======================================================');
let arr2 = ['foo','bar'];
let iter21 = arr2[Symbol.iterator]();
let iter22 = arr2[Symbol.iterator]();
console.log(iter21.next());
console.log(iter22.next());
console.log(iter21.next());
console.log(iter22.next());
// { value: 'foo', done: false }
// { value: 'foo', done: false }
// { value: 'bar', done: false }
// { value: 'bar', done: false }
console.log('=========================================================');
let arr3 = ['foo','baz'];
let iter3 = arr3[Symbol.iterator]();
console.log(iter3.next());
arr3.splice(1,0,'bar');
console.log(iter3.next());
console.log(iter3.next());
// { value: 'foo', done: false }
// { value: 'bar', done: false }
// { value: 'baz', done: false }
console.log('=============================================================');
 class Foo{
     [Symbol.iterator](){
         return {
             next(){
                 return {
                     done:false,
                     value:'bar'
                 }
             }
         }
     }
 }
 let f = new Foo();
 console.log(f[Symbol.iterator]());//{ next: [Function: next] }
 let arr4 = new Array();
 console.log(arr4[Symbol.iterator]())//Object [Array Iterator] {}
